<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Score extends Model
{
  use Notifiable;
  protected $table = 'scores';

  // 查询当日不同类型获取积分记录列表
  public static function getTodayScoreList($request)
  {
    $start_date = date('Y-m-d 00:00:00');
    $end_date = date('Y-m-d 23:59:59');
    $query = self::select('id', 'uid', 'type', 'type_desc', 'score')->whereBetween('created_at', [$start_date, $end_date]);
    if(isset($request->type) && $request->type) {
      $query->where('type', $request->type);
    }
    $res = $query->get();
    return $res ? $res->toArray():[];
  }

  // 查询今日签到及看广告积分信息
  public static function getSignAndAdScores() {
    $start_date = date('Y-m-d 00:00:00');
    $end_date = date('Y-m-d 23:59:59');
    $res = self::select('id', 'uid', 'type', 'type_desc', 'score')
          ->whereBetween('created_at', [$start_date, $end_date])
          ->where('type', 'sign')
          ->orWhere('type', 'watch_ad')
          ->get();
    return $res ? $res->toArray():[];
  }
}
